<?php

class Admin extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'yii_admins':
	 * @var integer $id
	 * @var string $username
	 * @var string $password
	 * @var integer $role_id
	 * @var integer $active
	 * @var string $change_time
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{admins}}';
	}

	public function scopes()
	{
		return array(
			'active'=>array(
				'condition'=>'t.active=1',
				'order'=>'t.id',
			),
		);
	}
	
	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('username, password, role_id, change_time', 'required'),
			array('role_id, active', 'numerical', 'integerOnly'=>true),
			array('username, password', 'length', 'max'=>60),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'Id',
			'username' => 'Username',
			'password' => 'Password',
			'role_id' => 'Role',
			'active' => 'Active',
			'change_time' => 'Change Time',
		);
	}
}